home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / cug236.zip / XC2.C < prev    next >
Text File  |  1980-01-02  |  29KB  |  1,040 lines

  1. /*
  2.     HEADER:        CUG000.00;
  3.     TITLE:        Cross Reference Generator;
  4.     DATE:        04/27/1988;
  5.     DESCRIPTION:    "C-language program cross-referencer, modified for
  6.                 Microsoft C5.0, with enhancements."
  7.     VERSION:    1.1;
  8.     KEYWORDS:    Cross Reference;
  9.     FILENAME:    XC2.C;
  10.     SEE-ALSO:    CUG126, CUG171;
  11.     COMPILERS:    Vanilla;
  12.     AUTHORS:    Phillip N. Hisley, David N. Smith, Fred C. Smith,
  13.             William C. Colley III;
  14. */
  15. /**********************************************************
  16.  
  17.     XC - A 'C' Concordance Utility
  18.  
  19.     Version 1.0 January, 1982
  20.  
  21.     Copyright (c) 1982 by Philip N. Hisley
  22.  
  23.         Philip N. Hisley
  24.         548H Jamestown Court
  25.         Edgewood, Maryland 21040
  26.         (301) 679-4606
  27.  
  28.     Released for non-commercial distribution only
  29.  
  30.  
  31.     Converted to IBM/PC CI/C86 by David N. Smith, May/June 1983
  32.     with enhancements and Lattice compiler support in December 1983.
  33.  
  34.         David N. Smith
  35.         44 Ole Musket Lane
  36.         Danbury, CT 06810
  37.         (203) 748-5934
  38.  
  39.     Changes Copyright (c) 1983 by David N. Smith
  40.  
  41.     PC Enhancements include:
  42.  
  43.         1)    Nested #INCLUDE statements
  44.         2)    Single spaced cross-reference list
  45.         3)    Removal of tabbing on output device
  46.         (Since many printers don't support it)
  47.         4)    #INCLUDE statements with both "--" and <-->
  48.         syntax and with a full fileid in the quotes.
  49.         5)    Multiple input filenames on command line.
  50.  
  51.  
  52.     Converted to Microsoft C V5.0 with enhancements.
  53.     November/December 1987.
  54.  
  55.         Fred C. Smith
  56.         20 Whipple Ave.
  57.         Stoneham, MA 02180
  58.  
  59.     Enhancements/modifications include:
  60.  
  61.     1)  Call to reargv() at beginning of main(). If you are running
  62.         Allen Holub's Unix-like shell, reargv() will rebuild argc/argv
  63.         to contain the 2kbyte command-line which the shell provides.
  64.         If not using that shell, reargv is a no-op. (That shell is
  65.         available from M&T Books for around $40, including source!)
  66.     2)  Modify the include file lookups to use the same algorithm as
  67.         used by the Microsoft C compiler, i.e., look first in the
  68.         current directory for quote-delimited files. If a complete
  69.         pathname is specified look there only then quit. Any remaining
  70.         includes, including '<' or '"' delimited ones are then
  71.         searched for in the place(s) (if any) specified in the
  72.         optional parameter to the -i switch. If not found there,
  73.         searches the pathname(s) specified in the INCLUDE environment
  74.         variable.
  75.     3)  Modify the -i switch so that an optional trailing argument
  76.         specifies an alternate path for the includes, as in the -I
  77.         switch in the Microsoft C compiler's "cl" command. Multiple
  78.         -i switches may be given, each with a single pathname. These
  79.         multiple pathnames are saved in the order given.
  80.     4)  Make the default behavior to assume that comments are NOT
  81.         nested. Some PC-based C compilers (e.g. Lattice) support
  82.         nested comments, but Microsoft's does not. Also, those on
  83.         Unix and other larger systems do not. The ANSI standard
  84.         does not. For those who prefer to have support for nested
  85.         comments, a new command-line switch has been added so that
  86.         you can (optionally) have your cake, and eat it, too!
  87.     5)  Add recognition of keywords recognized in ANSI C, i.e.,
  88.         const, enum, signed, volatile, void. Remove recognition of
  89.         entry as a keyword (not in ANSI C). Also, add optional
  90.         recognition of Microsoft-specific keywords: cdecl, far,
  91.         fortran, huge, near and pascal. Use the -m switch for this
  92.         last group.
  93.     6)  Fix the awful kludge which previously existed in xc, in
  94.         which struct rf_blk.ref_cnt was declared as an int, but
  95.         under certain circumstances was used to hold a pointer to
  96.         a struct rf_blk. Replaced the declaration of ref_cnt as
  97.         an int with an appropriately declared union of the two
  98.         types needed.
  99.     7)  Minor tweaks to proc_file to fix incorrect line numbers
  100.         being generated around included files.
  101.     8)  In fil_chr(), used ferror() and feof() to implement the
  102.         original error-checking logic which had been commented
  103.         out in previous versions of the code.
  104.  
  105.     Version 1.1 -- April 1988:
  106.  
  107.     Microsoft-isms removed by William C. Colley, III.  In particular
  108.     the function access() is not available in many environments.  A
  109.     reorganization of the code eliminates the use of this function.     Note,
  110.     however, that the function open_include_file() does chop on file names
  111.     which is an inherently non-portable operation, so that function will
  112.     have to be cut to fit different operating systems' file naming
  113.     conventions.  Also, the call to getenv() may have to be modified or
  114.     removed.
  115.  
  116.     Also, added the -x option to remove the directories specified in the
  117.     INCLUDE environment variable from the search path for #include files.
  118.     WCC3.
  119.  
  120.     Abstract:
  121.  
  122.     'XC' is a cross-reference utility for 'C' programs.  Its has the
  123.     ability to handle nested include files to a depth of 8 levels and
  124.     properly processes nested comments as supported by BDS C. Option flags
  125.     support the following features:
  126.  
  127.         - Routing of list output to disk
  128.         - Cross-referencing of reserved words
  129.         - Processing of nested include files
  130.         - Generation of listing only
  131.  
  132.     Usage: xc <filename> <flag(s)>
  133.  
  134.     Flags:    -i [pathname]      = Enable file inclusion
  135.         -l          = Generate listing only
  136.         -m          = recognize Microsoft-specific keywords
  137.         -n          = Allow nested comments
  138.         -o <filename>      = Write output to named file
  139.         -r          = Cross-ref reserved words
  140.         -w <width>      = Maximum listing width
  141.         -x          = Exclude default include file dir's
  142.  
  143.     Note:    For the -i option, the pathname is optional.  The -i flag may
  144.         be given multiple times, each time with a pathname. These
  145.         pathnames are saved, building a list of places to search for
  146.         include files.    If no list is given the standard places will
  147.         be used.  If the -i option flag is not used, includes will not
  148.         be cross-referenced.
  149.  
  150. ***********************************************************/
  151.  
  152. /* Compiler specific stuff */
  153.  
  154. #define LINT_ARGS
  155. #include <stdio.h>
  156. #include <stdlib.h>
  157. #include <ctype.h>
  158. #include <malloc.h>
  159. #include <string.h>
  160. #undef LINT_ARGS
  161.  
  162. /* end compiler specific section */
  163.  
  164. /* Function declarations for xc's routines. */
  165.  
  166. #include "xc.h"
  167.  
  168. #ifndef TRUE
  169. #define TRUE        1
  170. #define FALSE        0
  171. #endif
  172.  
  173. #define DUMMY        0        /* a dummy integer value */
  174. #define ERROR        -1
  175. #define MAX_REF        5        /* maximum refs per ref-block */
  176. #define MAX_LEN        20        /* maximum identifier length */
  177. #define MAX_WRD        749        /* maximum number of identifiers */
  178. #define MAX_ALPHA   53        /* maximum alpha chain heads */
  179. #define REFS_PER_LINE 10    /* maximum refs per line */
  180. #define LINES_PER_PAGE 60
  181. #define MAXCOL        78        /* default max column number for listing line */
  182. #define MINCOL        30        /* minimum value for -w option */
  183. #define PATHLEN        128        /* maximum pathname length in chars. */
  184. #define FF        0x0C    /* formfeed */
  185.  
  186. typedef union {
  187.     int cnt;
  188.     struct rf_blk *pnext;
  189. } cnt;
  190.  
  191. struct rf_blk {
  192.     int     ref_item[MAX_REF];
  193.     cnt ref_cnt;
  194. } onerf;
  195.  
  196. struct id_blk {
  197.     char id_name[MAX_LEN];
  198.     struct id_blk *alpha_lnk;
  199.     struct rf_blk *top_lnk;
  200.     struct rf_blk *lst_lnk;
  201. } oneid;
  202.  
  203. struct id_blk *id_vector[MAX_WRD];
  204.  
  205. struct alpha_hdr {
  206.     struct id_blk *alpha_top;
  207.     struct id_blk *alpha_lst;
  208. };
  209.  
  210. struct alpha_hdr alpha_vector[MAX_ALPHA];
  211.  
  212. int linum;        /* line number */
  213. int edtnum = 0;        /* edit line number */
  214. int fil_cnt = 0;    /* active file index */
  215. int wrd_cnt = 0;    /* token count */
  216. int pagno = 0;        /* page number */
  217. int id_cnt = 0;        /* number of unique identifiers */
  218. int rhsh_cnt = 0;    /* number of conflict hits */
  219. int filevl = 0;        /* file level  */
  220. int paglin = 0;        /* page line counter */
  221. int maxcol = MAXCOL;    /* maximum right column for listing line */
  222. int prt_ref = FALSE;
  223. char act_fil[PATHLEN];
  224. char lst_fil[PATHLEN];
  225. char gbl_fil[PATHLEN];
  226. char i_path[PATHLEN];
  227. FILE *f_lst_fil;
  228. int n_flg = FALSE;
  229. int i_flg = FALSE;
  230. int o_flg = FALSE;
  231. int r_flg = FALSE;
  232. int l_flg = FALSE;
  233. int m_flg = FALSE;
  234. int x_flg = FALSE;
  235.  
  236.  
  237. /*****************************